<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>编辑人员工作情况-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<style type="text/css">
.w250{ width: 250px; }
</style>
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">项目人员管理 > 编辑人员工作情况</div>
	</div>
	<div id="content">
	<form action="__APP__/Hr/project_user_edit" method="post" name="number_validate" id="password_validate" novalidate="novalidate">
			<input type="hidden" name="action" value="edit">
			<input type="hidden" name="uid" value="{$uid}">
			<input type="hidden" name="status" value="{$status}">
			<input type="hidden" name="fold" value="{$fold}">
			<input type="hidden" name="position_s" value="{$position}">
			<input type="hidden" name="rank_s" value="{$rank}">
			<input type="hidden" name="nature_s" value="{$nature}">
			<input type="hidden" name="keyword" value="{$keyword}">
			<input type="hidden" name="position_descr" value="{$user['position_descr']}">
			<div class="form-main">
				<div class="form-title">人员信息</div>
				<div class="form-item clearfix">
					<div class="item-float">
						<div class="input-label">用户名</div>
						<div class="input-item">{$user['username']}</div>
					</div>
					<div class="item-float">
						<div class="input-label">手机号</div>
						<div class="input-item">
							{$user['mobilephone']}
						</div>
					</div>
				</div>
				<div class="form-item clearfix">
					<div class="item-float">
						<div class="input-label">职位</div>
						<div class="input-item">
							{$user['position_descr']}
						</div>
					</div>
					<div class="item-float">
						<div class="input-label">职级</div>
						<div class="input-item">
							{$user['rank_descr']}
						</div>
					</div>
				</div>
				<div class="form-item clearfix">
					<div class="item-float">
						<div class="input-label">入职履历</div>
						<div class="input-group w250 left">
							<input type="text" name="file_name" class="form-control file-name" value="{$user['file_name']}" placeholder="请上传附件" <if condition="$user['file_url'] eq NULL">readonly</if> autocomplete="off">
							<span class="input-group-btn">
								<button class="btn file-submit" type="button">上传</button>
							</span>
						</div>
						<button <if condition="$user['file_url'] neq NULL">class="btn file-delete ml5"<else/>class="btn file-delete ml5 hide"</if> type="button">删除</button>
						<input type="hidden" name="file_url" class="file-url" value="{$user['file_url']}" autocomplete="off">
						<span class="error-item">文件名必填</span>
					</div>
				</div>
				<div class="form-title">工作情况</div>
				<div class="form-table-item">
					<table class="table">
						<tr class="form-table-header">
							<td width="27%"><span class="asterisk">*</span>项目名称</td>
							<td width="8%"><span class="asterisk">*</span>项目职务</td>
							<td width="8%"><span class="asterisk">*</span>职级</td>
							<td width="12%"><span class="asterisk">*</span>性质</td>
							<td width="12%"><span class="asterisk">*</span>派驻日期</td>
							<td width="8%">派出日期</td>
							<td width="12%">操作人(日期)</td>
							<td width="5%">操作</td>
						</tr>
						<!--<tr class="gz_tr2">
							<td>
								<select name="project_name[]" class="form-control w250 select-add hb_sid" autocomplete="off">
									<option value="-10" selected>请选择</option>
									<option value="">待分配</option>
									<foreach name="project_list" item="vo">
										<option value="{$vo['id']}">[{$vo['project_num']}]{$vo['project_name']}</option>
									</foreach>
								</select>
								<span class="error-item">必填项</span>
							</td>
							<td>
								<select name="post[]" class="form-control w150 select-add hb_sid" autocomplete="off">
									<option value="-10" selected>请选择</option>
									<foreach name="result4" item="vo">
										<option value="{$vo['id']}">{$vo['second_name']}</option>
									</foreach>
								</select>
								<span class="error-item">必填项</span>
							</td>
							<td>
								<select name="rank[]" class="form-control w150 select-add hb_sid" autocomplete="off">
									<option value="-10" selected>请选择</option>
									<foreach name="result5" item="vo">
										<option value="{$vo['second_name']}">{$vo['second_name']}</option>
									</foreach>
								</select>
								<span class="error-item">必填项</span>
							</td>
							<td>
								<select name="nature[]" class="form-control w150 select-add hb_sid" autocomplete="off">
									<option value="-10" selected>请选择</option>
									<option value="常驻">常驻</option>
									<option value="临时">临时</option>
								</select>
								<span class="error-item">必填项</span>
							</td>
							<td>
								<input name="come_date" type="text" class="form-control Wdate required-text w100" onclick="WdatePicker()" readonly autocomplete="off">
								<span class="error-item">必填项</span>
							</td>
							<td><span class="next_date"></span></td>
							<td></td>
							<td>
								<a href="javascript:;" class="data-add" data-toggle="tooltip" data-placement="bottom" title="添加"><i class="glyphicon glyphicon-plus"></i></a>
							</td>
						</tr>-->
						<foreach name="result" item="vo">
							<tr class='gz_tr'>
								<td><input type='hidden' name='project_name_copy[]' value="{$vo['pid']}"><if condition="$vo['project_num'] neq NULL">[{$vo['project_num']}]{$vo['project_name']}<else />待分配</if></td>
								<td><input type='hidden' name='post_copy[]' value="{$vo['post']}">{$vo['post_name']}</td>
								<td><input type='hidden' name='rank_copy[]' value="{$vo['rank']}">{$vo['rank']}</td>
								<td><input type='hidden' name='nature_copy[]' value="{$vo['nature']}">{$vo['nature']}</td>
								<td><input type='hidden' name='come_date_copy[]' value="{$vo['come_date']}">{$vo['come_date']}</td>
								<td><input type='hidden' name='out_date_copy[]' value="{$vo['out_date']}"><span class='next_date'>{$vo['out_date']}</span></td>
								<td>{$vo['add_user']}({$vo['add_date']|substr=0,10})</td>
								<td><a href="javascript:;" class="operate" id="{$vo['id']}" pid="{$vo['pid']}" uid="{$vo['uid']}" data-toggle="tooltip" data-placement="left" title="修改性质"><i class="glyphicon glyphicon-edit"></i></a></td>
								<!--<td><a href='javascript:;' <if condition="$key eq 0 and $vo['status'] eq 1">class='data-delete'<else />class='data-delete hide'</if> data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a></if></td>-->
							</tr>
						</foreach>
					</table>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn btn-submit" type="submit">提交</button><button class="btn btn-default js_back1" type="button">返回</button></div>
		</form>
	</div>
</div>
<!--对话框-->
<div class="modal fade" id="myModal-operate">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>操作提示框</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<table class="table table-bordered">
					<tr>
						<input type="hidden" name="pro_user_id" value="">
						<td class="text-right" width="100"><strong><span class="asterisk">*</span>性质</strong></td>
						<td>
							<select name="nature" class="form-control w150 select-add hb_sid" autocomplete="off">
								<option value="-10" selected>请选择</option>
								<option value="常驻">常驻</option>
								<option value="临时">临时</option>
							</select>
							<span class="error-item">必填项</span>
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-affirm">确认</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function() {
	//返回
	$(".js_back1").click(function(){
		document.location.href="__APP__/Hr/project_user/keyword/{$keyword}/status/{$status}/fold/{$fold}/p_status/{$p_status}/t_day/{$t_day}/nature/{$nature}&p={$page}";
	});
	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=user_cv";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
					}
				});
			});
		});
	});
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
		$(this).parents("tr").find(".required-text2").next(".error-item").hide();
	});
	//添加经营数据
	$(".data-add").on("click",function(){
		var state = true,
			custome = $(this).parents('tr');
			
		custome.find("[name='come_date']").each(function(){
			var val = $(this).val();
			if(val==""){
				$(this).nextAll(".error-item").eq(0).show();
				state = false;
			}else{
				var co_data = $("[name='come_date']").val();
				if($('.gz_tr').length>0){
					var prev_data = custome.next('tr').find("[name='come_date_copy[]']").val();
					function compareDate(date1, date2){
						let Y1 = parseInt(date1.substr(0, 4)),
							Y2 = parseInt(date2.substr(0, 4)),
							M1 = parseInt(date1.substr(5, 2)),
							M2 = parseInt(date2.substr(5, 2)),
							D1 = parseInt(date1.substr(8, 2)),
							D2 = parseInt(date2.substr(8, 2));
						let a = Y1 < Y2,
							b = Y1 == Y2 && M1 < M2,
							c = Y1 == Y2 && M1 == M2 && D1 <= D2;

						if (a || b || c) {
							return true;
						} else {
							return false;
						}
					}
					if(compareDate(co_data,prev_data)){
						
						defeated_alert("派驻日期不能小于上一次派驻日期");
						state = false;
					}
				}
			}
		})
		custome.find(".select-add").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).nextAll(".error-item").eq(0).show();
				state = false;
			}
		});
		
		$("[name='post']").each(function(){
			var val = $(this).val();
			if(val=="" || /^\s+$/.test(val)){
				$(this).nextAll(".error-item").eq(0).show();
				state = false;
			}
		});
		
		if(state){
			var tr = $(this).parents("tr"),
				table = $(this).parents("table"),
				pro = $("[name='project_name[]']").val(),
				pro_op = $("[name='project_name[]']").find('option:selected').text(),
				rank = $("[name='rank[]']").val(),
				rank_op = $("[name='rank[]']").find('option:selected').text(),
				post = $("[name='post[]']").val(),
				post_op = $("[name='post[]']").find('option:selected').text(),
				nat = $("[name='nature[]']").val(),
				nat_op = $("[name='nature[]']").find('option:selected').text(),
				co_data = $("[name='come_date']").val(),
				co_data_rep =co_data.replace(/[&\|\\\*^%$#@\-]/g,""),
				html = "";
			html+= "<tr class='gz_tr'><td><input type='hidden' name='project_name_copy[]' value='"+pro+"'>"+pro_op+"</td><td><input type='hidden' name='post_copy[]' value='"+post+"'>"+post_op+"</td><td><input type='hidden' name='rank_copy[]' value='"+rank+"'>"+rank_op+"</td><td><input type='hidden' name='nature_copy[]' value='"+nat+"'>"+nat_op+"</td><td><input type='hidden' name='come_date_copy[]' value='"+co_data+"'>"+co_data+"</td><td><input type='hidden' name='out_date_copy[]' value=''><span class='next_date'></span></td><td></td><td><a href='javascript:;' class='data-delete' data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a></td></tr>";
			table.find(".error-item").hide();
			table.find(".select2,.tooltip").remove();
			table.find("select").val(-10);
			table.find("[name='come_date']").val('');
			setTimeout(function(){
				table.find(".data-delete").tooltip({trigger:'hover'});
			},200);
			tr.after(html);
			table.find("tr select").select2();
			$('.table tr').eq(3).find('.next_date').html(co_data);
			$('.table tr').eq(3).find("[name='out_date_copy[]']").val(co_data);
			$('.table tr').eq(3).find('.data-delete').addClass('hide');
		}
	});
	
	//删除计划任务
	$(document).on("click",".data-delete",function(){
		$(this).parents("tr").next('tr').find('.data-delete').removeClass('hide');
		$(this).parents("tr").next('tr').find('.next_date').html('');
		$(this).parents("tr").next('tr').find("[name='out_date_copy[]']").val('');
		$(this).parents("tr").remove();
	});
	
	//表单验证
	$(".btn-submit").click(function(e){
		var tag = false,
			gz_l = $(".gz_tr").length;
		
		if(gz_l < 1){
			defeated_alert("至少添加一条工作情况");
			tag = true;
		}
		$("[name='mobilephone']").each(function(){
			var val = $(this).val();
			if(val==""){
				$(this).nextAll(".error-item").eq(0).show();
				tag = true;
			}else if(val!="" && !/^1[3|4|5|7|8]\d{9}$/.test(val)){
				$(this).nextAll(".error-item").eq(1).show();
				tag = true;
			}
		});
		$("[name='position_id']").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		$("[name='rank_id']").each(function(){
			var val = $(this).val();
			if(val==-10){
				$(this).nextAll(".error-item").show();
				tag = true;
			}
		});
		$(".file-name").each(function(){
			var val = $(this).val();
			if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
				$(this).parents(".input-group").nextAll(".error-item").show();
				tag = true;
			}
		});
		$(".file-url").each(function(){
			var val = $(this).val();
			if(val!=""){
				$(this).parents("tr").find(".required-text2").each(function(){
					var val2 = $(this).val();
					if(val2=="" || /^\s+$/.test(val2)){
						$(this).next(".error-item").show();
						tag = true;
					}
				});
			}
		});
		if(tag){
			return false;
		}
	});
	
	//隐藏错误提示
	$(".required-text").focus(function(){
		$(this).nextAll(".error-item").hide();
	});
	$(".checkbox-item").on('click',":checkbox",function(){
		$(this).parents(".checkbox-item").find(".error-item").hide();
	});
	$("select.select-add").change(function(){
		$(this).nextAll(".error-item").hide();
	});
	$(".file-name").on("focus",function(){
		$(this).parents(".input-group").nextAll(".error-item").hide();
	});

	//编辑
    $(".operate").on("click",function(){
        var pro_user_id = $(this).attr("id");
        $("[name='pro_user_id']").val(pro_user_id);
        $("#myModal-operate").removeClass('fade');
        $("#myModal-operate").show();
    });
    //关闭按钮
    $(".fa-times,.btn-default").on("click",function(){
        $("#myModal-operate").addClass('fade');
        $("#myModal-operate").hide();
    });
    //确认操作
    $("#myModal-operate").find(".btn-affirm").on("click",function(){
        var tag = true,
            modal = $("#myModal-operate");
        if(tag){
            var id = $("[name='pro_user_id']").val(),
                nature = $("[name='nature']").val()
            modal.hide();
            $.ajax({
                type:"POST",
                asnyc:false,
                dataType:"json",
                data:{"id":id,"nature":nature},
                url:"__APP__/Project/project_user_edit",
                success:function(data){
                    success_pop(data['status'],data['msg']);
                }
            });
        }
    });
});
</script>
</body>
</html>